package com.sgb.kjwl.viewmodel.home;

import android.text.TextUtils;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.BiddingEntity;
import com.sgb.jicai.entity.CentralizedMiningEntity;
import com.sgb.jicai.entity.JiCaiHomeListRequestBean;
import com.sgb.kjwl.model.entity.lease.AskLeaseSheBeiEntity;
import com.sgb.kjwl.model.entity.lease.LeaseListEntity;
import com.sgb.kjwl.model.entity.request.CarFilterJson;
import com.sgb.kjwl.model.entity.request.FactoryFilterJson;
import com.sgb.kjwl.model.entity.request.FarmFilterJson;
import com.sgb.kjwl.model.entity.request.HouseFilterJson;
import com.sgb.kjwl.model.entity.request.LandFilterJson;
import com.sgb.kjwl.model.entity.request.LeaseAskFilterJson;
import com.sgb.kjwl.model.entity.request.LeaseMachineFilterJson;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.swgk.core.base.model.entity.H5ReEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.sgb.kjwl.view.ui.fragment.home.LeaseListFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class LeaseListFragmentModel extends BaseViewModel {
    private HomeRepertory repertory;
    private LeaseListFragment fragment;
    public int pageSize = 10;
    public int pageNum = 1;
    public String isSelf;//是否自营

    public LeaseListFragmentModel(LeaseListFragment fragment, HomeRepertory repertory) {
        this.fragment = fragment;
        this.repertory = repertory;
    }

    /**
     * 求租详情
     *
     * @param categoryType
     * @param id
     */
    public void getH5UrlByAskLease(String categoryType, String id) {
        String urlName = "";
        if ("1".equals(categoryType)) {//机械
            urlName = "mechanicsRentDetails";
        } else if ("2".equals(categoryType)) {//设备
            urlName = "equipmentRentDetails";
        } else if ("3".equals(categoryType)) {//车辆
            urlName = "vehicleRentDetails";
        } else if ("4".equals(categoryType)) {//房产
            urlName = "houseRentDetails";
        } else if ("5".equals(categoryType)) {//土地
            urlName = "landRentDetails";
        } else if ("6".equals(categoryType)) {//工厂
            urlName = "factoryRentDetails";
        } else if ("7".equals(categoryType)) {//农机
            urlName = "farmRentDetails";
        }
        if (TextUtils.isEmpty(urlName)) {
            return;
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting(urlName).enqueue(new Callback<BaseEntity<H5ReEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<H5ReEntity>> call, Response<BaseEntity<H5ReEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    String url = response.body().getData().getUrl() + "?id=" + id;
//                    WebViewX5HostActivity.start(fragment.getActivity(), url);
                    WebViewX5HostActivity.start(fragment.getActivity(), url, id, "asklease", categoryType);
                } else {
                    MToast.showToast(fragment.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<H5ReEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /**
     * 出租详情
     *
     * @param type
     * @param id
     */
    public void getH5Url(String type, String id) {
        String name = "";
        if ("1".equals(type)) {
            name = "mechanicsDetail";//机械
        } else if ("2".equals(type)) {
            name = "equipmentDetails";//设备
        } else if ("3".equals(type)) {
            name = "vehicleDetails";//车辆
        } else if ("4".equals(type)) {
            name = "propertyDetails";//房产
        } else if ("5".equals(type)) {
            name = "landDetails";//土地
        } else if ("6".equals(type)) {
            name = "factoryDetails";//工厂
        } else if ("7".equals(type)) {
            name = "farmDetail";//农机
        }
        if (TextUtils.isEmpty(name)) {
            return;
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting(name).enqueue(new Callback<BaseEntity<H5ReEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<H5ReEntity>> call, Response<BaseEntity<H5ReEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    String url = response.body().getData().getUrl() + "?id=" + id + "&iosFlag=1";
//                    WebViewX5HostActivity.start(fragment.getActivity(), url);
                    WebViewX5HostActivity.start(fragment.getActivity(), url, id, "lease", type);
                } else {
                    MToast.showToast(fragment.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<H5ReEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /**
     * 竞价租赁详情
     *
     * @param id
     */
    public void getUrlSetting(String id) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting("competitivePurchase").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String url = data.getData().getUrl() + "?id=" + id;
                    String lng = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
                    String lat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
                    url = url + "&lng=" + lng + "&lat=" + lat;
                    WebViewX5HostActivity.start(fragment.getActivity(), url, id);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    /**
     * 集采详情
     *
     * @param id
     */
    public void getH5UrlByJC(String id) {
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting("collection").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {//type 0 首页 1 我的集采 2 我的报价
                    SharedPreferenceUtil.init(fragment.getActivity());
                    String token = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.resourceAPPToken, "");
                    String url = data.getData().getUrl() + "?id=" + id + "&type=0" + "&token=" + token;
                    WebViewX5HostActivity.start(fragment.getActivity(), url);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    //获取一级类型
    public void getFilterTypeModel(String type) {
        APIManager.getInstance().getLeaseMapAPI().getFistcategory(type).enqueue(new Callback<BaseEntity<List<DictEntity3>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<DictEntity3>>> call, Response<BaseEntity<List<DictEntity3>>> response) {
                if (response.body() == null || response.body().getState() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.showCategoryList(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<DictEntity3>>> call, Throwable t) {
            }
        });

    }

    //获取招采集采一级类型
    public void getFilterTypeModel(String no, String type) {
        APIManager.getInstance().getMachineAPI().getSecondCategory(no, type).enqueue(new Callback<BaseEntity<List<DictEntity3>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<DictEntity3>>> call, Response<BaseEntity<List<DictEntity3>>> response) {
                if (response.body() == null || response.body().getState() == null) return;
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.showCategoryList(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<DictEntity3>>> call, Throwable t) {
            }
        });

    }

    /**
     * 热门推荐
     *
     * @param pos
     * @param firstCategoryNo
     * @param isLoadMore
     */
    public void getHomeRecommend(int pos, String firstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        String type = (pos == 0) ? "" : String.valueOf(pos);
        Map map = new HashMap();
        map.put("provinceNo", repertory.getAreaCode());
        map.put("current", pageNum);
        map.put("limit", pageSize);
        map.put("type", type);
        map.put("firstCategoryNo", firstCategoryNo);
        map.put("hasVideo", "1");
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getHomeLeaseAPI().getHomeRecommend(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<LeaseListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null) {
                    fragment.showList(data.getData(), isLoadMore);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                fragment.showList(new ListResponse<>(), isLoadMore);
            }
        });
    }

    /**
     * 出租大厅 全部/机械列表
     *
     * @param isLoadMore
     */
    public void getMachineModel(int pos, String firstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        LeaseMachineFilterJson filterJson = new LeaseMachineFilterJson();
        filterJson.setHasVideo("1");
        filterJson.setFirstCategoryNo(firstCategoryNo);
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
//        filterJson.setProvinceNo(repertory.getAreaCode());
        filterJson.setType(pos == 0 ? "" : String.valueOf(pos));
        filterJson.setIsSelf(isSelf);
        filterJson.setSortWay("");//设置为空，则不排序
        filterJson.setDistanceSort("2");
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson).enqueue(new ICallBack<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<LeaseListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null) {
                    fragment.showList(data.getData(), isLoadMore);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                fragment.showList(new ListResponse<>(), isLoadMore);
            }

        });
    }

    //获取车辆筛选列表
    public void getAllListByCar(String FirstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        CarFilterJson filterJson = new CarFilterJson();
        filterJson.setHasVideo("1");
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
        filterJson.setModelId(FirstCategoryNo);
        filterJson.setBrandId("");
//        filterJson.setProvinceNo(repertory.getAreaCode());
        filterJson.setType("3");
        filterJson.setIsSelf(isSelf);
        filterJson.setSortWay("");//设置为空，则不排序
        filterJson.setDistanceSort("2");
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson).enqueue(new ICallBack<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<LeaseListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null) {
                    fragment.showList(data.getData(), isLoadMore);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                fragment.showList(new ListResponse<>(), isLoadMore);
            }

        });
    }


    //获取房产筛选列表
    public void getAllListByHouse(String FirstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        HouseFilterJson filterJson = new HouseFilterJson();
        filterJson.setHasVideo("1");
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
        filterJson.setSortWay("");//设置为空，则不排序
        filterJson.setCategoryParentId(FirstCategoryNo);
        filterJson.setCategoryChildId("");
        filterJson.setRentalArea("");
//        filterJson.setProvinceNo(repertory.getAreaCode());
        filterJson.setType("4");
        filterJson.setIsSelf(isSelf);
        filterJson.setDistanceSort("2");
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson).enqueue(new ICallBack<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<LeaseListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null) {
                    fragment.showList(data.getData(), isLoadMore);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                fragment.showList(new ListResponse<>(), isLoadMore);
            }

        });
    }


    //获取土地筛选列表
    public void getAllListByLand(String FirstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        LandFilterJson filterJson = new LandFilterJson();
        filterJson.setHasVideo("1");
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
        filterJson.setSortWay("");//设置为空，则不排序
        filterJson.setFirstCategoryNo(FirstCategoryNo);
        filterJson.setSecondCategoryNo("");
        filterJson.setRentalArea("");
//        filterJson.setProvinceNo(repertory.getAreaCode());
        filterJson.setType("5");
        filterJson.setIsSelf(isSelf);
        filterJson.setDistanceSort("2");
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson).enqueue(new ICallBack<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<LeaseListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null) {
                    fragment.showList(data.getData(), isLoadMore);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                fragment.showList(new ListResponse<>(), isLoadMore);
            }

        });
    }

    //获取工厂筛选列表
    public void getAllListByFactory(String FirstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        FactoryFilterJson filterJson = new FactoryFilterJson();
        filterJson.setHasVideo("1");
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
        filterJson.setSortWay("");//设置为空，则不排序
        filterJson.setFirstCategoryNo(FirstCategoryNo);
        filterJson.setSecondCategoryNo("");
        filterJson.setRentalArea("");
//        filterJson.setAreacode(repertory.getAreaCode());
        filterJson.setType("6");
        filterJson.setIsSelf(isSelf);
        filterJson.setDistanceSort("2");
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson).enqueue(new ICallBack<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<LeaseListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null) {
                    fragment.showList(data.getData(), isLoadMore);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                fragment.showList(new ListResponse<>(), isLoadMore);
            }

        });
    }

    //获取农机筛选列表
    public void getAllListByFram(String FirstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        FarmFilterJson filterJson = new FarmFilterJson();
        filterJson.setHasVideo("1");
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
        filterJson.setSortWay("");//设置为空，则不排序
        filterJson.setFirstCategoryNo(FirstCategoryNo);
        filterJson.setSecondCategoryNo("");
//        filterJson.setAreacode(repertory.getAreaCode());
        filterJson.setType("7");
        filterJson.setIsSelf(isSelf);
        filterJson.setDistanceSort("2");
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson).enqueue(new ICallBack<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<LeaseListEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null) {
                    fragment.showList(data.getData(), isLoadMore);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                fragment.showList(new ListResponse<>(), isLoadMore);
            }

        });
    }

    /**
     * 求租信息
     *
     * @param categoryType
     * @param classNo
     * @param isLoadMore
     */
    public void getDataList(String categoryType, String classNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        LeaseAskFilterJson filterJson = new LeaseAskFilterJson();
        filterJson.setHasVideo("1");//需查询视频
        filterJson.setProvinceNo(repertory.getAreaCode());
        filterJson.setCityNo("");
        filterJson.setCurrent(pageNum);
        filterJson.setSortWay("1");
        filterJson.setAreaNos(new ArrayList<>());
        filterJson.setType(categoryType);
        filterJson.setFirstCategoryNo(classNo);
        getAskRentLeaseAll(filterJson, isLoadMore);
    }

    public void getAskRentLeaseAll(LeaseAskFilterJson leaseAskFilterJson, boolean isLoadMore) {
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getMachineAPI().getAskRentLeaseAll(leaseAskFilterJson).enqueue(new Callback<BaseEntity<ListResponse<List<AskLeaseSheBeiEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<AskLeaseSheBeiEntity>>>> call, Response<BaseEntity<ListResponse<List<AskLeaseSheBeiEntity>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if (null != response.body().getData()) {
                        fragment.showListAskLease(response.body().getData(), isLoadMore);
                    } else {
                        MToast.showToast(fragment.getActivity(), "暂无数据");
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<AskLeaseSheBeiEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }


    /**
     * 竞价租赁
     *
     * @param goodsType
     * @param b
     */
    public void getBiddingList(String type, String goodsType, boolean b) {
        HashMap map = new HashMap();
        pageNum = b ? pageNum + 1 : 1;
        map.put("limit", 10);
        map.put("name", "");
        map.put("page", pageNum);
        if (TextUtils.isEmpty(type)) {//模块类型，type ="1"//机械，type ="5"//设备
            map.put("typeValue", "1和5");
        } else {
            map.put("type", type);
        }
        map.put("areacode", repertory.getAreaCode());
        map.put("goodsType", goodsType);;//一级分类
        map.put("sortMethod", "1");
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getBiddingList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<BiddingEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<BiddingEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() != null) {
                    fragment.showBindingList(data.getData().getList(), b);
                } else {
                    fragment.showBindingList(new ArrayList<>(), b);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<BiddingEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                fragment.showBindingList(new ArrayList<>(), b);
            }
        });
    }


    /**
     * 需方发起列表
     */
    public void getJiCaiList(JiCaiHomeListRequestBean map, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        map.setProvinceNo(repertory.getAreaCode());
        map.setCurrent(pageNum);
        map.setLimit(10);
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getCentralizedMiningAPI().getJiCaiLists(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<CentralizedMiningEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<CentralizedMiningEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() != null) {
                    fragment.setJiCaiList(data.getData().getList(), isLoadMore);
                } else {
                    fragment.setJiCaiList(new ArrayList<>(), isLoadMore);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<CentralizedMiningEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                fragment.setJiCaiList(new ArrayList<>(), isLoadMore);
            }
        });
    }
}
